<?php
class UsersControllerTest extends CakeTestCase {
    function startCase() {
        echo '<h2>User Controller</h2>';
    }
    function endCase() {
    }
    function startTest($method) {
        echo '<h3>Starting method ' . $method . '</h3>';
    }
    function endTest($method) {
        echo '<hr />';
    }
    function testView() {
        $vars = $this->testAction('/users/view/5', 'vars');
        $user_data = $vars['user_data']['User'];

        // Check if all data is loaded correctly
        $this->assertEqual($user_data['id'], 5);
        $this->assertEqual($user_data['facebook_id'], 0);
        $this->assertEqual($user_data['name'], 'Nguyen Thanh Trung');
        $this->assertEqual($user_data['username'], 'invincible_kid23@yahoo.com');
        $this->assertEqual($user_data['avatar'], 'avatar/544851c6c17d5b59f6fe22f223db85aa.jpg');
        $this->assertEqual($user_data['gender'], 1);
        $this->assertEqual($user_data['role'], 0);

        $view = $this->testAction('/users/view/5', 'view');
        // Check if the javascript is linked properly
        $this->assertPattern('/\<script type="text\/javascript" src="\/dealcruncher\/js\/cart.js"\>/', $view);
        $this->assertPattern('/\<script type="text\/javascript" src="\/dealcruncher\/js\/jquery.mCustomScrollbar.js"\>/', $view);
        $this->assertPattern('/\<script type="text\/javascript" src="\/dealcruncher\/js\/jquery.mousewheel.min.js"\>/', $view);

        // Check if css is loaded properly
        $this->assertPattern('/\<link rel="stylesheet" type="text\/css" href="\/dealcruncher\/css\/profile.css" \/>/', $view);
        $this->assertPattern('/\<link rel="stylesheet" type="text\/css" href="\/dealcruncher\/css\/category.css" \/>/', $view);
        $this->assertPattern('/\<link rel="stylesheet" type="text\/css" href="\/dealcruncher\/css\/deal.css" \/>/', $view);
        $this->assertPattern('/\<link rel="stylesheet" type="text\/css" href="\/dealcruncher\/css\/jquery.mCustomScrollbar.css" \/>/', $view);

        // Check main contents
        $this->assertPattern('/\<div id="catmain"\>/', $view);
        $this->assertPattern('/\<div class="title" style="margin: 30px">SELLING ITEMS\<\/div\>/', $view);
        // $this->assertPattern('/\<a href="" class="dtitle"\>Amazon Kindle Paperwhite\<\/a\>/', $view);
    }
    function testProfile() {
        $vars = $this->testAction('/users/profile', 'vars');
        $user_data = $vars['user']['User'];

        // Check if user data is loaded correctly
        // $this->assertEqual($user_data['id'], 12);
        // $this->assertEqual($user_data['facebook_id'], 0);
        // $this->assertEqual($user_data['name'], 'Nguyen Thanh Trung');
        // $this->assertEqual($user_data['username'], 'ngthanhtrung23@gmail.com');
        // $this->assertEqual($user_data['avatar'], 'default.jpg');
        // $this->assertEqual($user_data['gender'], 1);
        // $this->assertEqual($user_data['role'], 1);

        $view = $this->testAction('/users/profile', 'view');
        // Check if the javascript is linked properly
        $this->assertPattern('/\<script type="text\/javascript" src="\/dealcruncher\/js\/modify_image.js"\>/', $view);

        // Check if css is loaded properly
        $this->assertPattern('/\<link rel="stylesheet" type="text\/css" href="\/dealcruncher\/css\/form.css" \/>/', $view);

        // Check main contents
        $this->assertPattern('/\<div class="form_wrapper"\>/', $view);
        $this->assertPattern('/\<div class="title">Edit Profile\<\/div\>/', $view);
        $this->assertPattern('/\<label\>Name\<\/label\>/', $view);
        $this->assertPattern('/maxlength="255" value="Nguyen Thanh Trung" id="UserName"/', $view);
    }
}
?>
